/**
 * 
 */
package com.estock.platform.http.response;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.estock.common.model.security.RealTimeTrans;
import com.estock.common.util.StringUtil;

/**
 * @author richard
 *
 */
public class SinaRealTimeStockBulkResponse extends SinaBaseResponse {
	
	List<RealTimeTrans> realTimeTrans = new ArrayList<RealTimeTrans>();
	public List<RealTimeTrans> getRealTimeTrans() {
		return realTimeTrans;
	}

	@Override
	protected void parse(String sinaJsString) {
		if (StringUtils.isEmpty(sinaJsString)) {
			throw new RuntimeException();
		}
		String[] tempArr = sinaJsString.split("=");
		String[] values = tempArr[1].replace("\"", "").split(",");
		
		RealTimeTrans bean = new RealTimeTrans();
		bean.setCode(tempArr[0].substring(tempArr[0].length() - 6, tempArr[0].length()));
		bean.setOpenPrice(Double.valueOf(values[1]));
		bean.setLastClosePrice(Double.valueOf(values[2]));
		bean.setCurrentPrice(Double.valueOf(values[3]));
		bean.setHighPrice(Double.valueOf(values[4]));
		bean.setLowPrice(Double.valueOf(values[5]));
		bean.setBuy1Price(Double.valueOf(values[6]));
		bean.setSell1Price(Double.valueOf(values[7]));
		bean.setVolumeSum(Double.valueOf(values[8]));
		bean.setTurnOver(Double.valueOf(values[9]));
		bean.setBuy1Vol(Integer.valueOf(values[10]));
		bean.setBuy1Price(Double.valueOf(values[11]));
		bean.setBuy2Vol(Integer.valueOf(values[12]));
		bean.setBuy2Price(Double.valueOf(values[13]));
		bean.setBuy3Vol(Integer.valueOf(values[14]));
		bean.setBuy3Price(Double.valueOf(values[15]));
		bean.setBuy4Vol(Integer.valueOf(values[16]));
		bean.setBuy4Price(Double.valueOf(values[17]));
		bean.setBuy5Vol(Integer.valueOf(values[18]));
		bean.setBuy5Price(Double.valueOf(values[19]));
		bean.setSell1Vol(Integer.valueOf(values[20]));
		bean.setSell1Price(Double.valueOf(values[21]));
		bean.setSell2Vol(Integer.valueOf(values[22]));
		bean.setSell2Price(Double.valueOf(values[23]));
		bean.setSell3Vol(Integer.valueOf(values[24]));
		bean.setSell3Price(Double.valueOf(values[25]));
		bean.setSell4Vol(Integer.valueOf(values[26]));
		bean.setSell4Price(Double.valueOf(values[27]));
		bean.setSell5Vol(Integer.valueOf(values[28]));
		bean.setSell5Price(Double.valueOf(values[29]));
		bean.setSdate(StringUtil.parseDate(values[30]));
		bean.setStime(values[31]);
		
		realTimeTrans.add(bean);
	}
}
